package com.fivefu.core.hik.controller;

import com.alibaba.fastjson.JSON;
import com.fivefu.base.common.utils.str.StrUtils;
import com.fivefu.base.web.controller.BaseController;
import com.fivefu.base.web.vo.ResultInfo;
import com.fivefu.core.hik.services.CameraService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 海康监控点表 前端控制器
 * </p>
 *
 * @author 
 * @since 2022-07-05 09:15:14
 */
@Api(tags = "监控点管理")
@RestController
@RequestMapping("/db-hik-camera")
public class DbHikCameraController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(DbHikCameraController.class);

    @Autowired
    private CameraService cameraService;

    @ApiOperation(value = "获取监控点列表",httpMethod = "POST",response = ResultInfo.class,notes = "查询监控点列表")
    @RequestMapping(path = "getCameraList",method = RequestMethod.POST)
    @ApiImplicitParam(name = "version", value = "版本", required = true, paramType = "query", dataType = "int")
    public ResultInfo getCameraList(Integer version){
        try {
            if (version == null){
                return ResultInfo.renderError("版本号不能为空");
            }
            cameraService.getCameraList(version);
            return ResultInfo.renderSuccess("获取监控点列表成功");
        } catch (Exception e){
            logger.error(e.getMessage(),e);
        }
        return ResultInfo.renderError("获取监控点列表失败");
    }

    @ApiOperation(value = "获取区域监控点关联关系",httpMethod = "GET",response = ResultInfo.class,notes = "获取区域监控点关联关系")
    @RequestMapping(path = "queryRegionCamera",method = RequestMethod.GET)
    public ResultInfo queryRegionCamera(){
        try {
            cameraService.queryCameraByRegionIndexCode();
            return ResultInfo.renderSuccess("获取区域监控点关联关系成功");
        } catch (Exception e){
            logger.error(e.getMessage(),e);
        }
        return ResultInfo.renderError("获取区域监控点关联关系失败");
    }

    @ApiOperation(value = "查询监控点详情",httpMethod = "POST",response = ResultInfo.class,notes = "查询监控点详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cameraIndexCode",value = "监控点编号",required = true,paramType = "query",dataType = "String")
    })
    @RequestMapping(path = "/queryCameraDetail",method = RequestMethod.POST)
    public ResultInfo queryCameraDetail(String cameraIndexCode) {
            try {
                if (StrUtils.isNull(cameraIndexCode)) {
                    return ResultInfo.renderError("监控点编号不能为空");
                }
                cameraService.queryCameraDetail(cameraIndexCode);
                return ResultInfo.renderSuccess("查询监控点详情成功");
            } catch (Exception e) {
                logger.error(e.getMessage(),e);
                return ResultInfo.renderError("查询监控点详情失败");
            }
    }

    @ApiOperation(value = "增量获取监控点数据",httpMethod = "POST",response = ResultInfo.class,notes = "增量获取监控点数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stime",value = "更新开始时间（例：2019-08-06T14:01:17.839+0800）",required = true,paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "etime",value = "更新结束时间（例：2019-08-06T14:01:17.839+0800）",required = false,paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页码",required = true,paramType = "query",dataType = "Integer"),
            @ApiImplicitParam(name = "limit",value = "每页显示数量",required = true,paramType = "query",dataType = "Integer")
    })
    @RequestMapping(path = "/queryCameraData",method = RequestMethod.POST)
    public ResultInfo queryCameraData(String stime,String etime,Integer page,Integer limit) {
        logger.info("增量获取监控点数据请求参数为：" + JSON.toJSONString(request.getParameterMap()));
        try {
            if (StrUtils.isNull(stime)) {
                return ResultInfo.renderError("更新开始时间不能为空");
            }
            if (null == page) {
                return ResultInfo.renderError("页码不能为空");
            }
            if (null == limit) {
                return ResultInfo.renderError("每页显示数量不能为空");
            }
            cameraService.queryCameraData(stime,etime,page,limit);
            return ResultInfo.renderSuccess("增量获取监控点数据成功");
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            return ResultInfo.renderError("增量获取监控点数据失败");
        }
    }

    @ApiOperation(value = "根据监控点编号查询监控点详情",httpMethod = "POST",response = ResultInfo.class,notes = "根据监控点编号查询监控点详情")
    @RequestMapping(path = "/getAllCameraDetail",method = RequestMethod.POST)
    public ResultInfo getAllCameraDetail() {
        try {
            cameraService.getAllCameraDetail();
            return ResultInfo.renderSuccess("根据监控点编号查询监控点详情成功");
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            return ResultInfo.renderError("根据监控点编号查询监控点详情失败");
        }
    }
}
